package com.ruoyi.estate.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.estate.domain.BusinessFloor;
import com.ruoyi.estate.service.IBusinessFloorService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 楼栋管理Controller
 * 
 * @author 博雅
 * @date 2023-12-19
 */
@RestController
@RequestMapping("/estate/floor")
public class BusinessFloorController extends BaseController
{
    @Autowired
    private IBusinessFloorService businessFloorService;

    /**
     * 查询楼栋管理列表
     */
    @PreAuthorize("@ss.hasPermi('estate:floor:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusinessFloor businessFloor)
    {
        startPage();
        List<BusinessFloor> list = businessFloorService.selectBusinessFloorList(businessFloor);
        return getDataTable(list);
    }

    /**
     * 导出楼栋管理列表
     */
    @PreAuthorize("@ss.hasPermi('estate:floor:export')")
    @Log(title = "楼栋管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusinessFloor businessFloor)
    {
        List<BusinessFloor> list = businessFloorService.selectBusinessFloorList(businessFloor);
        ExcelUtil<BusinessFloor> util = new ExcelUtil<BusinessFloor>(BusinessFloor.class);
        util.exportExcel(response, list, "楼栋管理数据");
    }

    /**
     * 获取楼栋管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('estate:floor:query')")
    @GetMapping(value = "/{floorId}")
    public AjaxResult getInfo(@PathVariable("floorId") Long floorId)
    {
        return success(businessFloorService.selectBusinessFloorByFloorId(floorId));
    }

    /**
     * 新增楼栋管理
     */
    @PreAuthorize("@ss.hasPermi('estate:floor:add')")
    @Log(title = "楼栋管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusinessFloor businessFloor)
    {
        return toAjax(businessFloorService.insertBusinessFloor(businessFloor));
    }

    /**
     * 修改楼栋管理
     */
    @PreAuthorize("@ss.hasPermi('estate:floor:edit')")
    @Log(title = "楼栋管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusinessFloor businessFloor)
    {
        return toAjax(businessFloorService.updateBusinessFloor(businessFloor));
    }

    /**
     * 删除楼栋管理
     */
    @PreAuthorize("@ss.hasPermi('estate:floor:remove')")
    @Log(title = "楼栋管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{floorIds}")
    public AjaxResult remove(@PathVariable Long[] floorIds)
    {
        return toAjax(businessFloorService.deleteBusinessFloorByFloorIds(floorIds));
    }

    /**
     * 获取楼栋树列表
     */
    @PreAuthorize("@ss.hasPermi('estate:room:list')")
    @GetMapping("/floorTree")
    public AjaxResult floorTree()
    {
        return success(businessFloorService.selectFloorTreeList());
    }

    //查询所有楼栋
    @PreAuthorize("@ss.hasPermi('estate:room:list')")
    @GetMapping("/floorList")
    public AjaxResult floorList()
    {
        return success(businessFloorService.selectBusinessFloorList(null));
    }
}
